import Page
from Page import SmartHome
from Base.Base import Base
from selenium.webdriver.common.by import By


class SmartHomeXiaomiLoginPage(Base):
    """
    小米登陆页

    因其页面命名比较特殊, 故直接采用拼音命名
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.smarthome_xiaomi_home_btn = (By.XPATH, SmartHome.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.smarthome_xiaomi_back_btn = (By.XPATH, SmartHome.RESOURCE_ID.format('ivBack'))

        # 小米登录标题
        self.smarthome_xiaomi_login_title_text = (By.XPATH, SmartHome.RESOURCE_ID.format("tv_title"))

        # 小米登录二维码图标
        self.smarthome_xiaomi_qr_code_img = (By.XPATH, SmartHome.RESOURCE_ID.format("iv_code"))

        # 小米登录提示
        self.smarthome_xiaomi_prompt_text = (By.XPATH, SmartHome.RESOURCE_ID.format("tv_lable"))

        # 小米右侧文本,从上往下,默认值为1
        self.smarthome_xiaomi_list_prompt_right_text = (By.XPATH, SmartHome.xiaomi_login_list_prompt_text.format(1))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.smarthome_xiaomi_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.smarthome_xiaomi_back_btn)

    def get_xiaomi_login_title(self):
        """
        获取小米页标题

        :return: 获取元素
        """
        return self.find_element_o(self.smarthome_xiaomi_login_title_text)

    def get_xiaomi_qr_code(self):
        """
        获取小米页二维码

        :return: 获取元素
        """
        return self.find_element_o(self.smarthome_xiaomi_qr_code_img)

    def get_xiaomi_prompt(self):
        """
        获取小米页登录提示

        :return: 获取元素
        """
        return self.find_element_o(self.smarthome_xiaomi_prompt_text)

    def get_list_xiaomi_list_prompt_right(self, index=1):
        """
        获取右侧文本

        :param index:1
        :return: 获取元素
        """
        self.smarthome_xiaomi_list_prompt_right_text = (By.XPATH, SmartHome.xiaomi_login_list_prompt_text.format(index))
        return self.find_element_o(self.smarthome_xiaomi_list_prompt_right_text)

    def is_display_smart_home_xiaomi(self):
        """
        是否进入智能家居首页界面

        :return: bool
        """
        return self.is_display(self.smarthome_xiaomi_login_title_text)
